﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Serialization;

using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.Common.Security;
using ScrumTable.DL.Data.Schema;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.DL.Data.Schema.Serialization
{
    /// <summary>
    /// Represents the serializer for schema serialization or deserialization.
    /// </summary>
    public class SchemaSerializer
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new SchemaSerializer instance.
        /// </summary>
        public SchemaSerializer()
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Deserializes the given data storage. The given file system path
        /// is used in order to retrieve the data from the file system in xml format.
        /// </summary>
        /// <param name="xmlString">Specifies the xml string to deserialize.</param>
        public SchemataRoot Deserialize(string xmlString)
        {
            PreCondition.AssertNotNullOrEmpty(xmlString, "xmlString");

            using (var dataReader = new StringReader(xmlString))
            {
                return (SchemataRoot)CreateSerializer().Deserialize(dataReader);
            }
        }

        private XmlSerializer CreateSerializer()
        {
            return new XmlSerializer(typeof(SchemataRoot));
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}